package com.medreams.dao;

import com.medreams.domain.Order;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface OrderDao {

    @Select("select * from test_other")
    @Results(
            id = "orderMapper",//此id是方便其他方法调用 主要作用就是当实体类domain中的字段名与数据库不一致时使用此 关联查询时也会用到
            value = {//对于单个Result 无需填写 若是多个必写
                @Result(id=true,column = "id",property = "orderId"),
//              此时建立一对一关系 one many 是建立一对一的关系 fetchType 是选择实时加载还是选择延迟加载 一般一对一实时 对多延迟 test_id作为外键参数传递过去
//                @Result(column = "test_id",property = "testId"),
                @Result(column = "test_id",property = "user",one = @One(select="com.medreams.dao.UserDao.getTestInfo",fetchType = FetchType.EAGER)),
                @Result(column = "other_name",property = "otherName"),
                @Result(column = "other_title",property = "otherTitle"),
                @Result(column = "create_time",property = "createTime")
            }

    )
    List<Order> orderList();

    @Select("select * from test_other where id = #{id}")
    @ResultMap({"orderMapper"})//直接引用已经注释的字段映射
    List<Order> getOrderList(Integer id);

}
